import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { User } from '@/types/user.d.ts'


// 用户store
export const useUserStore = defineStore('jz-user', () => {
  //全局变量登录用户
  // 空对象的变量通过 as 断言指定类型(意思就是我确定返回的就是这个类型)
  const users = ref({} as User)
  //方法1：存储用户信息=》登录成功
  const setUserData = (userData: User) =>{
    users.value = userData
  }
  //方法2：删除用户信息
  const delUserData = () => {
    users.value = {} as User
  }

  //返回变量和方法
  return {
    users,
    setUserData,
    delUserData
  }
})
